package com.stx.system;

import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * @author awhacker
 * @version 1.8
 * @Package com.stx.system
 * @Title: uTools
 * @Date 2024/3/23 13:25
 * @Mail 2663922541@qq.com
 * @description: ${--description}
 */
public class uTools {
    static Scanner sc = new Scanner(System.in);

    // 判断成绩
    public static double determineScore( double stuScore) {
        boolean isValid;
        do {
            isValid = true;
            try {
                System.out.print("请输入你的成绩(double类型)!");

                stuScore = sc.nextDouble();
                if (stuScore >= 0 && stuScore <= 100) {
                    System.out.println("成绩输入成功!!");
                } else {
                    isValid = false;
                    System.out.println("成绩范围不正确,请输入(0-100)之间的成绩:");
                }
            } catch (InputMismatchException e) {
                System.out.println("Error: You did not enter an Double. Please enter an Double.");
                isValid = false; // 设置标志以重新提示输入
                sc.reset(); // 重置扫描器的状态
                sc.nextLine();
            }
        } while (!isValid); // 循环直到用户输入有效的整数
        return stuScore;
    }

//    判断性别
    public static String deterSex(String stuSex ){
         stuSex = StudentService.getInputStrByTip("请输入性别：(只能输入男/女,输入其他默认是人妖)");
        if (stuSex.equals("男")) {
            stuSex = "男";
        } else if (stuSex.equals("女")) {
            stuSex = "女";
        } else {
            stuSex = "人妖";
        }
        return stuSex;
    }

//    判断年龄
    public static int deterAge(int age){
        while (true) {
            String stuAge = StudentService.getInputStrByTip("请输入年龄：");
            //将字符串"20"->20
            if (Display.parseToInt(stuAge)) {
                age = Integer.parseInt(stuAge);
                if (Integer.parseInt(stuAge) < 0 || Integer.parseInt(stuAge) > 256) {
                    System.out.println("请输入人类的正常寿命,谢谢!!");
                } else {
                    System.out.println("恭喜您,年龄输入正确!");
                    break;
                }
            } else {
                System.out.println("您输入年龄有误，请重试！");
            }

        }
        return age;
    }

//    判断手机号码
    public static String deterStuNum(String stuPhone){
        boolean phoneFlag = false;
        while (!phoneFlag) {
            stuPhone = StudentService.getInputStrByTip("请输入联系方式：");
            if (StudentService.isValidPhoneNumber(stuPhone) && StudentService.stuPhoneRepeat(stuPhone) == false) {
                phoneFlag = true;
                System.out.println("恭喜您手机号验证成功");
            } else if (StudentService.stuPhoneRepeat(stuPhone)) {
                System.out.println("您输入的电话号码重复了!!!");
            } else {
                System.out.println("您输入的电话号码格式有误");

            }
        }
        return stuPhone;
    }
}
